package ch.zbw.sysventory.agent.scanner;

import org.apache.log4j.Logger;

import ch.zbw.sysventory.agent.scanner.impl.ComputerScannerImpl;
import ch.zbw.sysventory.agent.scanner.xml.ScanResultXmlWriterFactory;
import ch.zbw.sysventory.transport.model.ScanResult;

public class ComputerScanManager extends Thread implements Runnable {

	private Logger logger = Logger.getRootLogger();
	private ComputerScanner scanner;

	public ComputerScanManager() {
		// change this to other scanner when finished !!!
		this.scanner = new ComputerScannerImpl();
	}

	@Override
	public void run() {
		while (!isInterrupted()) {
			try {
				logger.info("Start scan computer now.");
				ScanResult scanResult = this.scanner.scanComputer();
				logger.info("Computer scanned. Write to XML file now ...");
				ScanResultXmlWriterFactory.getScanResultXmlWriter().writeScanResultToXml(scanResult);
				Thread.sleep(300000);
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
				interrupt();
			}
		}
	}

}
